<?php
use QL\QueryList;
class NewsAction extends CommonAction {
	public function classindex() {
		parent::userauth2(45);
		$newsclass = D('Newsclass');
		import('ORG.Util.Page');		// 导入分页类
		$count = $newsclass->count();			//总记录数
		$Page = new Page($count,15);		//实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('header','条记录');
		$Page->setConfig('prev','<img src="__IMAGE__/prev.gif" border="0" title="上一页" />');
		$Page->setConfig('next','<img src="__IMAGE__/next.gif" border="0" title="下一页" />');
		$Page->setConfig('first','<img src="__IMAGE__/first.gif" border="0" title="第一页" />');
		$Page->setConfig('last','<img src="__IMAGE__/last.gif" border="0" title="最后一页" />');
		$show = $Page->show();			//分页显示输出
		$volist=$newsclass->relation(true)->order('Dtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();		
		$this->assign('volist',$volist);
		$this->assign('page',$show);
		$this->co=$count;
		$this->display();
	}

	//添加分类
	public function classadd() {
		parent::win_userauth(46);
		$this->display();
	}
	//添加分类处理
	public function classadd_do() {
		parent::userauth(46);
		if ($this->isAjax()) {
			$data = array();
			$data['ClassName'] = I('post.classname','');
			$data['Aliases'] = I('post.aliases','');
			$data['Description'] = I('post.description');
			$newsclass = D('Newsclass');
			//自动创建并验证数据
			if ($newsclass->create($data)) {
				$newsclass->add();
				parent::operating(__ACTION__,0,'新增成功');
				R('Public/errjson',array('ok'));
			}else {
				parent::operating(__ACTION__,1,'新增失败:'.$newsclass->getError());
				R('Public/errjson',array($newsclass->getError()));
			}
		}else {
			parent::operating(__ACTION__,1,'非法请求');
			R('Public/errjson',array('非法请求'));
		}
	}
	//修改分类
	public function classedit() {
		parent::win_userauth(47);
		$id = I('get.id','');
		if ($id=='' || !is_numeric($id)) {
			parent::operating(__ACTION__,1,'参数错误');
			$this->content='参数ID类型错误，请关闭本窗口';
			exit($this->display('Public:err'));
		}
		$id=intval($id);
		$newsclass=M('newsclass');
		if ($result=$newsclass->where("ID=$id")->find()) {
			$this->result=$result;
			$this->display();
		}else {
			parent::operating(__ACTION__,1,'数据不存在');
			$this->content='没有找到相关数据，请关闭本窗口';
			$this->display('Public:err');
		}
	}
	//修改分类处理
	public function classedit_do() {
		parent::userauth(47);
		if ($this->isAjax()) {
			$data = array();
			$data['ID'] = I('post.id','');
			$data['ClassName'] = I('post.classname','');
			$data['Aliases'] = I('post.aliases','');
			$data['Description'] = I('post.description');
			$newsclass = D('Newsclass');
			//自动创建并验证数据
			if ($newsclass->create($data)) {
				$newsclass->save();
				parent::operating(__ACTION__,0,'更新成功');
				R('Public/errjson',array('ok'));
			}else {
				parent::operating(__ACTION__,1,'更新失败'.$newsclass->getError());
				R('Public/errjson',array($newsclass->getError()));
			}
		}else {
			parent::operating(__ACTION__,1,'非法请求');
			R('Public/errjson',array('非法请求'));
		}
	}
	//删除分类
	public function classdel() {
		//验证用户权限
		parent::userauth(48);
		//判断是否是ajax请求
		if ($this->isAjax()) {
			$id = I('post.id','');
			if ($id=='' || !is_numeric($id)) {
				parent::operating(__ACTION__,1,'参数错误');
				R('Public/errjson',array('参数ID类型错误'));
			}else {
				$id=intval($id);
				$newsclass=M('newsclass');
				if ($newsclass->where("ID=$id")->delete()) {
					parent::operating(__ACTION__,0,'删除成功');
					R('Public/errjson',array('ok'));
				}else {
					parent::operating(__ACTION__,1,'删除失败');
					R('Public/errjson',array('数据不存在'));
				}
			}
		}else {
			parent::operating(__ACTION__,1,'非法请求');
			R('Public/errjson',array('非法请求'));
		}
	}
	
	//内容管理
	public function news() {
        parent::userauth2(84);
		//验证用户权限
        $data['start'] = empty($_GET['page'])?0:($_GET['page']-1)*10;
        $data['pageSize'] = 10;
        $html = send_post(C('URL').'/eduWeb/news/querySysNewsList',$data);
        //dump($html);
        $count = $html['data']['count'];
        import('ORG.Util.Page');				// 导入分页类
        $pagenum = isset ( $_REQUEST ['page'] ) ? $_REQUEST ['page'] : 1;
        $page_row = 10;//每页显示条数
        $p = new Page ($count,$page_row,8);
        $p->isJumpPage = true;
        $p->setConfig('theme','%totalRow% %header% %nowPage%/%totalPage% 页%first% %upPage% %linkPage% %downPage% %end% %jump%');
        $show = $p->show();
        $this->assign('volist',$html['data']['newsList']);
        $this->assign('page',$show);
        $this->assign('url',C('URL'));
		$this->display();
	}

	//添加内容
	public function add() {
        parent::userauth2(84);
		$newsclass = M('newsclass');
		$clist = $newsclass->order('Dtime asc')->select();
		$this->assign('clist',$clist);
        $this->assign('userId',$_SESSION['ThinkUser']['ID']);
        $this->assign('url',C('URL'));
		$this->display();
	}

	//更新文章
	public function edit() {
        $newsclass = M('newsclass');
        $clist = $newsclass->order('ID asc')->select();
        $this->clist=$clist;
        $data['sid']= $_GET['sid'];
        $html = send_post(C('URL').'/eduWeb/news/newsDetail',$data);
        $this->assign('news',$html['data']);
        //dump($html);
        $this->assign('url',C('URL'));
        $this->assign('userId',$_SESSION['ThinkUser']['ID']);
        $this->display();
	}

	//合作院校
	public function school(){
		$data['start'] = empty($_GET['page'])?0:($_GET['page']-1)*10;
        $data['pageSize'] = 10;
        $html = send_post(C('URL').'/eduWeb/news/getSchoolList',$data);
        //dump($html);
        $count = $html['data']['count'];
        import('ORG.Util.Page');				// 导入分页类
        $pagenum = isset ( $_REQUEST ['page'] ) ? $_REQUEST ['page'] : 1;
        $page_row = 10;//每页显示条数
        $p = new Page ($count,$page_row,8);
        $p->isJumpPage = true;
        $p->setConfig('theme','%totalRow% %header% %nowPage%/%totalPage% 页%first% %upPage% %linkPage% %downPage% %end% %jump%');
        $show = $p->show();
        $this->assign('school',$html['data']['newList']);
        $this->assign('page',$show);
        $this->assign('url',C('URL'));
		$this->display();
	}


	//合作院校
	public function hot(){
		$data['start'] = empty($_GET['page'])?0:($_GET['page']-1)*10;
        $data['pageSize'] = 10;
        $html = send_post(C('URL').'/eduWeb/news/getHotList',$data);
        //dump($html);
        $count = $html['data']['count'];
        import('ORG.Util.Page');				// 导入分页类
        $pagenum = isset ( $_REQUEST ['page'] ) ? $_REQUEST ['page'] : 1;
        $page_row = 10;//每页显示条数
        $p = new Page ($count,$page_row,8);
        $p->isJumpPage = true;
        $p->setConfig('theme','%totalRow% %header% %nowPage%/%totalPage% 页%first% %upPage% %linkPage% %downPage% %end% %jump%');
        $show = $p->show();

        $this->assign('hot',$html['data']['newList']);
        $this->assign('page',$show);
        $this->assign('url',C('URL'));
		$this->display();
	}


	//合作基地
	public function base(){
		$data['start'] = empty($_GET['page'])?0:($_GET['page']-1)*10;
        $data['pageSize'] = 10;
        $html = send_post(C('URL').'/eduWeb/news/getBaseList',$data);
        //dump($html);
        $count = $html['data']['count'];
        import('ORG.Util.Page');				// 导入分页类
        $pagenum = isset ( $_REQUEST ['page'] ) ? $_REQUEST ['page'] : 1;
        $page_row = 10;//每页显示条数
        $p = new Page ($count,$page_row,8);
        $p->isJumpPage = true;
        $p->setConfig('theme','%totalRow% %header% %nowPage%/%totalPage% 页%first% %upPage% %linkPage% %downPage% %end% %jump%');
        $show = $p->show();
        $this->assign('base',$html['data']['newList']);
        $this->assign('page',$show);
        $this->assign('url',C('URL'));
		$this->display();
	}

}
?>